package org.learn.java.mq.util;

import java.security.MessageDigest;
import java.util.zip.CRC32;

public class HashUtil {
	
	
	public static void main(String[] args) {
		long value = crc32Code("why it's not good?".getBytes());
		System.out.println("value:"+value);
		String mdvalue = md5Code("why it's not good?".getBytes());
		System.out.println("value:"+mdvalue);
	}

	/**
	 * CRC32信息摘要
	 * @param value
	 * @return
	 */
	public static long crc32Code(byte[] value){
		CRC32 crc32 = new CRC32();
		crc32.update(value);
		return crc32.getValue();
	}
	
	public static String md5Code(byte[] value){
		MessageDigest md = null;
		String result = null;
		try {
			md = MessageDigest.getInstance("MD5");
			byte[] mdvalue = md.digest(value);
			result = new String(mdvalue);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
}
